import { AllParams, PostParams } from './ts/http'

const BaseFetch = {
  GET: (allParams: AllParams) => {
    const {url, params, header, otherConfigure} = allParams;
    return fetch(url, {
      method: 'GET',
      headers: {
        ...header
      },
      // mode: "cors", // "no-cors",
      // credentials: 'include',
      ...otherConfigure,
    })
  },
  POST: (allParams: PostParams) => {
    const {url, params, header, otherConfigure} = allParams;

    return fetch(url, {
      method: 'POST',
      body: params.constructor === String ? params : JSON.stringify(params),
      headers: {
        // 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
        // ...authenticationObj(params),
        ...header
      },
      // 带上 cookie
      // credentials: "include",
      ...otherConfigure,
    })
  },
  PUT: (allParams: AllParams) => {

  },
  DELETE: (allParams: AllParams) => {

  }
}


export default BaseFetch
